#pragma once

#include "..\\headers.default.h"
#include "..\\headers.cv.h"
#include "..\\headers.classification.h"

using namespace loirey;

class CImagePositionFeatureExtractor : public CSingleDataForClassification
{
public:
	int ImageHandle;
	int QueryX, QueryY;

public:
	virtual ~CImagePositionFeatureExtractor();
public:
	virtual CImagePositionFeatureExtractor* myClone() = 0;
	virtual void ClearContent() = 0;
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "") = 0;
	virtual int GetFeatureDimension() = 0;
	virtual int RecomputeFeatureDimension() = 0;
	virtual double GetFeature(int FeatureIndex) = 0;
public:
	virtual size_t GetMemoryUsage() const;
public:
	virtual void SetQuery(int x, int y);
	virtual double GetFeature(int x, int y, int FeatureIndex);
};

class CImagePositionFeatureCalculator
{
public:
	int ImageHandle;

public:
	virtual ~CImagePositionFeatureCalculator()
	{	}
public:
	virtual CImagePositionFeatureCalculator* myClone() const = 0;
	virtual void ClearContent() = 0;
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "") = 0;
	virtual int GetFeatureDimension() = 0;
	virtual int RecomputeFeatureDimension() = 0;
	virtual void CalcFeature(
		int x, int y, int FeatureIndex,
		double* DstData, bool* DstGotFlag
		) = 0;
	virtual size_t GetMemoryUsage() const = 0;
};

class CBasicIPFE : public CImagePositionFeatureExtractor
{
public:
	int Dim;
	CImagePositionFeatureCalculator* pIPFC;
	int LastX, LastY;
	CSimpleTypeArray<double> FeatureCache;
	CSimpleTypeArray<bool> FeatureFlag;

protected:
	void myRelease();
public:
	CBasicIPFE();
	CBasicIPFE(CImagePositionFeatureCalculator* pInitializedIPFC);
	CBasicIPFE(const CBasicIPFE& AnotherInstance);
	virtual CBasicIPFE& operator = (const CBasicIPFE& AnotherInstance);
	virtual ~CBasicIPFE();
public:
	void myInit(CImagePositionFeatureCalculator* pInitializedIPFC);
	virtual void ClearCalculationHistory();
public:
	virtual CImagePositionFeatureExtractor* myClone();
	virtual void ClearContent();
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "");
	virtual int GetFeatureDimension();
	virtual int RecomputeFeatureDimension();
	virtual double GetFeature(int FeatureIndex);
	virtual size_t GetMemoryUsage() const;
};

class CCompositeIPFC : public CImagePositionFeatureCalculator
{
public:
	int Dim;
	CSimpleTypeArray<CImagePositionFeatureCalculator*> IPFCList;
	CSimpleTypeArray<int> FeatureStart;

protected:
	void myRelease();
	void Clear_IPFC_List_WithoutDeletion();
public:
	CCompositeIPFC();
	CCompositeIPFC(const CCompositeIPFC& AnotherInstance);
	virtual CCompositeIPFC& operator = (const CCompositeIPFC& AnotherInstance);
	virtual ~CCompositeIPFC();
public:
	void Clear_IPFC_List();
	void PushBack(CImagePositionFeatureCalculator* pInitializedIPFC);
	void myInit(const CCompositeIPFC& AnotherInstance);
public:
	virtual CImagePositionFeatureCalculator* myClone() const;
	virtual void ClearContent();
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "");
	virtual int GetFeatureDimension();
	virtual int RecomputeFeatureDimension();
	virtual void CalcFeature(
		int x, int y, int FeatureIndex,
		double* DstData, bool* DstGotFlag
		);
	virtual size_t GetMemoryUsage() const;
};

class C_IPFC_ResponseUser
{
public:
	virtual ~C_IPFC_ResponseUser()
	{
	}
public:
	virtual C_IPFC_ResponseUser* myClone() const = 0;
	virtual size_t GetMemoryUsage() const = 0;
	virtual int GetInputResonseDimension() const = 0;
	virtual int GetFeatureDimension() const = 0;
	virtual int RecomputeFeatureDimension() = 0;
	virtual void ClearContent() = 0;
	virtual void SetInputResponse(const double* pSrcResponse, int W, int H) = 0;
	virtual void ComputeFeature(int x, int y, int FeatureIndex, double* DstData, bool* DstGotFlag) = 0;
};

class C_IPFC_ImageFilterBankOwner : public CImagePositionFeatureCalculator
{
public:
	CImageFilterBank* pIFB;
	bool fSharedIFB;
	int ImageExtent;
public:
	int W, H, WH;
	//int eW, eH, eWH;
public:
	int UserAmount;
	int FeatureDimension;
	int InputResponseDimension;
	CSimpleTypeArray<C_IPFC_ResponseUser*> UserList;
	CSimpleTypeArray<bool> AreUserInitializedList;
	CSimpleTypeArray<int> UserFeatureStartList;
	CSimpleTypeArray<int> UserInputResponseStartList;
	CSimpleTypeArray<int> UserInputResponseIndexList;

public:
	C_IPFC_ImageFilterBankOwner();
	C_IPFC_ImageFilterBankOwner(CImageFilterBank* pNewIFB, int ImageExtent, bool fSharedIFB);
	C_IPFC_ImageFilterBankOwner(const C_IPFC_ImageFilterBankOwner& AnotherInstance);
	virtual C_IPFC_ImageFilterBankOwner& operator = (const C_IPFC_ImageFilterBankOwner& AnotherInstance);
	virtual ~C_IPFC_ImageFilterBankOwner();
	void CloneWithoutContentFrom(const C_IPFC_ImageFilterBankOwner& AnotherInstance);
	void InitImageFilterBank(CImageFilterBank* pNewIFB, int ImageExtent, bool fSharedIFB);
	void ClearResponseUserSet();
	void PushBackResponseUser(C_IPFC_ResponseUser* pNewUser, const int* pInputResponseIndex);
public:
	virtual void ClearContent();
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "");
	virtual size_t GetMemoryUsage() const;
	virtual int GetFeatureDimension();
	virtual int RecomputeFeatureDimension();
public:
	virtual CImagePositionFeatureCalculator* myClone() const;
	virtual void CalcFeature(
		int x, int y, int FeatureIndex,
		double* DstData, bool* DstGotFlag);
};

////class CFilterResponseIPFC : public CImagePositionFeatureCalculator
////{
////public:
////	CImageFilterBank* pImageFilterBank;
////	int ImageExtent;
////	CSimpleTypeArray<int> InputResponseList;
////public:
////	int W, H, V;
////	size_t WH, WHV;
////
////protected:
////	void myRelease();
////public:
////	CFilterResponseIPFC();
////	CFilterResponseIPFC(CImageFilterBank* pFixedImageFilterBank, int ImageExtent, const CSimpleTypeArray<int>& InputResponseList);
////	CFilterResponseIPFC(const CFilterResponseIPFC& AnotherInstance);
////	void InitResponseInputSettings(CImageFilterBank* pFixedImageFilterBank, int ImageExtent, const CSimpleTypeArray<int>& InputResponseList);
////	void ClearResponseData();
////public:
////	virtual ~CFilterResponseIPFC();
////public:
////	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName = "");
////public:
////	virtual CImagePositionFeatureCalculator* myClone() const = 0;
////	virtual void SetResponseImage(const double* SrcResponse) = 0;
////	virtual int GetFeatureDimension() = 0;
////	virtual int RecomputeFeatureDimension()
////	{
////		return GetFeatureDimension();
////	}
////	virtual void CalcFeature(
////		int x, int y, int FeatureIndex,
////		double* DstData, bool* DstGotFlag
////		) = 0;
////public:
////	virtual size_t GetMemoryUsage() const;
////};

